#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :file_demo.py
# @Time      :2023/6/30 
# @Author    :CL
# @email     :1037654919@qq.com

import json
import pandas as pd
import os
import shutil

def readname(filePath):
    # filePath = 'pinterest/'
    name = os.listdir(filePath)
    return name

def clean_data(filePath):
    "清洗pinterest数据，先在文件夹里边搜索jpg,批量删除不要的图片，再打开程序，运行程序，删除相应文件夹：判断逻辑：文件夹里边文件小于3"
    name = readname(filePath)
    for i in name[:]:
        path2= filePath+'/{}/'.format(i)
        name2 = os.listdir(path2)
        if len(name2)<=2:
            # shutil.rmtree(path2)
            print(i,len(name2))
def count_file(path):
    try:
        name = os.listdir(path)
        return len(name)
    except:
        return 0


if __name__ == "__main__":
    # name = readname('pinterest/')
    # for na in name:
    #     filepath = 'pinterest/{}/'.format(na)
    #     clean_data(filepath)
    path = 'pinterest/'
    name = os.listdir(path)
    count = 0
    for na in name:
        filepath = 'pinterest/{}/'.format(na)
        print(filepath)
        count += count_file(filepath)
    print(count)